﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using limpalex.bbparser.Interfaces;

namespace limpalex.bbparser.Converters
{
    class BooleanConverter : IValueConverter
    {
        public object Convert(XmlNode value)
        {
            return ConvertFromString(value.InnerText);
        }

        public object ConvertFromString(string value)
        {
            switch (value.ToUpper())
            {
                case "Y":
                    return true;
                case "YES":
                    return true;
                case "TRUE":
                    return true;
                case "N":
                    return false;
                case "NO":
                    return false;
                case "FALSE":
                    return false;
                default:
                    throw new ArgumentOutOfRangeException("value");
            }
        }
    }
}
